package acwing._1_1AlgorithmBasic._5DynamicProgramming;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @Project : AlgorithmLearning
 * @Package : ACWing._1_1AlgorithmBasic._5DynamicProgramming
 * @File : Q0898.java
 * @Author : WangRuoyu
 * @Date 2023/11/25 11:10
 */

public class Q0898 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] line = br.readLine().split(" ");
        final int N = Integer.parseInt(line[0]);

        int[][] f = new int[N][N];

        for (int i = 0; i < N; i++) {
            line = br.readLine().split(" ");
            for (int j = 0; j <= i; j++) {
                f[i][j] = Integer.parseInt(line[j]);
            }
        }

        int res = -0x3f3f3f3f;
        for (int i = 1; i < N; i++) {
            for (int j = 0; j <= i; j++) {
                int add = -0x3f3f3f3f;
                if (j > 0) add = Math.max(add, f[i - 1][j - 1]);
                if (j < i) add = Math.max(add, f[i - 1][j]);
                f[i][j] += add;
                if (i == N - 1) res = Math.max(res, f[i][j]);
            }
        }

        System.out.println(res);
    }
}